import 'package:flutter/material.dart';
import 'package:flutter_app/generated/l10n.dart';
class TextFieldEye extends StatefulWidget {
  TextFieldEye({
    Key key,
    @required this.onChanged,
  });

  final ValueChanged<String> onChanged;

  @override
  _TextFieldEyeState createState() => _TextFieldEyeState();
}

class _TextFieldEyeState extends State<TextFieldEye> {
  bool showPsw = false;

  @override
  Widget build(BuildContext context) {
    return TextField(
      obscureText: !showPsw,
      decoration: InputDecoration(
        //six_psw 6位数字密码
        hintText: S.of(context).six_psw,
        hintStyle: TextStyle(color: Colors.grey, height: 2.2),
        contentPadding: EdgeInsets.only(right: 10.0),
        enabledBorder: UnderlineInputBorder(
            borderSide: BorderSide(color: Color(0xffB6B6B6), width: 0.5)),
        suffixIcon: IconButton(
            onPressed: () {
              setState(() {
                showPsw = !showPsw;
              });
            },
            icon: ImageIcon(AssetImage(showPsw
                ? "assets/images/ic_eye_open.png"
                : "assets/images/ic_eye_close.png"))),
      ),
      onChanged: (v) {
        //将选中状态通过事件的形式抛出
        widget.onChanged(v);
      },
    );
  }
}
